package com.cwm.test.adapter.v2;

import com.cwm.test.adapter.v2.adapter.*;

public class PassportForThirdAdapter extends PassportService implements IPasswordForThird {


    public ResultMsg processLogin(String id, Class<? extends ILoginAdapter> clazz) {
        try {
            ILoginAdapter adapter = clazz.newInstance();
            if (adapter.support(adapter)) {
                return adapter.login(id, adapter);
            }
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return null;
    }


    @Override
    public ResultMsg loginForQQ(String username, String password) {
        return processLogin(username, LoginForQQAdapter.class);
    }

    @Override
    public ResultMsg loginForWechat(String openid) {
        return processLogin(openid, LoginForWechatAdapter.class);
    }

    @Override
    public ResultMsg loginForToken(String token) {
        return processLogin(token, LoginForTokenAdapter.class);
    }

    @Override
    public ResultMsg loginForTelphone(String openid, String code) {
        return processLogin(openid, LoginForTelphoneAdapter.class);
    }


}
